<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
    <script>
        function dispatch(action) {
            if (typeof action !== "object") {
                throw new Error("action必须是一个对象")
            } else {
                if (!action.type) {
                    throw new Error("action中必须有一个type字段")
                } else {
                    console.log('通过')
                }
            }
        }

        // 保存源代码
        const oldDispatch = dispatch
        // 覆盖源代码
        dispatch = (action) => {
            if (typeof action === "function") {
                console.log('我可以写函数了')
            } else {
                oldDispatch(action)
            }
        }

        dispatch(() => {
            axios.get('/url').then(res => {
                dispatch({ type: "INIT", list: res.data })
            })
        })


        // dispatch({ type: "a" })
    </script>
</body>
</html>